tools/ocaml/xenctrl: Make domain_getinfolist tail recursive
authorEdwin Török <edvin.torok@citrix.com>
Tue, 1 Nov 2022 17:59:16 +0000 (17:59 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 9 Feb 2023 15:55:25 +0000 (15:55 +0000)
commit03f545b6cf3220b4647677b588e5525a781a4813
tree7aa071c52c8ede314042d839bee27094c8f4e3ed
parent3dae50283d9819c691a97f15b133124c00d39a2f
tools/ocaml/xenctrl: Make domain_getinfolist tail recursive

domain_getinfolist() is quadratic with the number of domains, because of the
behaviour of the underlying hypercall.  xenopsd was further observed to be
wasting excessive quantites of time manipulating the list of already-obtained
domains.

Implement a tail recursive `rev_concat` equivalent to `concat |> rev`, and use
it instead of calling `@` multiple times.

An incidental benefit is that the list of domains will now be in domid order,
instead of having pairs of 2 domains changing direction every time.

In a scalability testing scenario with ~1000 VMs, a combination of this and
the subsequent change takes xenopsd's wallclock time in domain_getinfolist()
down from 88% to 0.02%

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Tested-by: Pau Ruiz Safont <pau.safont@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
(cherry picked from commit c3b6be714c64aa62b56d0bce96f4b6a10b5c2078)
tools/ocaml/libs/xc/xenctrl.ml